Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@protobuf-ts/runtime

Package Overview
Dependencies
Maintainers
1
Versions
113
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@protobuf-ts/runtime

Runtime library for code generated by the protoc plugin "protobuf-ts"

  • 2.9.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
286K
decreased by-16.5%
Maintainers
1
Weekly downloads
 
Created

What is @protobuf-ts/runtime?

@protobuf-ts/runtime is a runtime library for Protocol Buffers in TypeScript. It provides utilities for encoding, decoding, and working with Protocol Buffers messages in a TypeScript environment.

What are @protobuf-ts/runtime's main functionalities?

Encoding Messages

This feature allows you to encode a Protocol Buffers message into a binary format. The code sample demonstrates how to define a message class, create an instance of the message, and encode it.

const { Message, WireType } = require('@protobuf-ts/runtime');

class MyMessage extends Message {
  static readonly runtime = { fields: [{ no: 1, name: 'field1', kind: 'scalar', T: 9 /* string */ }] };
  field1 = '';
}

const message = new MyMessage({ field1: 'Hello, World!' });
const binary = MyMessage.encode(message).finish();
console.log(binary);

Decoding Messages

This feature allows you to decode a binary Protocol Buffers message back into a message object. The code sample demonstrates how to decode a binary message into an instance of the message class.

const { Message, WireType } = require('@protobuf-ts/runtime');

class MyMessage extends Message {
  static readonly runtime = { fields: [{ no: 1, name: 'field1', kind: 'scalar', T: 9 /* string */ }] };
  field1 = '';
}

const binary = new Uint8Array([10, 13, 72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33]);
const message = MyMessage.decode(binary);
console.log(message);

Message Reflection

This feature provides reflection capabilities for Protocol Buffers messages, allowing you to inspect the fields and types of a message at runtime. The code sample demonstrates how to access the runtime information of a message class.

const { Message, WireType } = require('@protobuf-ts/runtime');

class MyMessage extends Message {
  static readonly runtime = { fields: [{ no: 1, name: 'field1', kind: 'scalar', T: 9 /* string */ }] };
  field1 = '';
}

const message = new MyMessage({ field1: 'Hello, World!' });
console.log(MyMessage.runtime.fields);

Other packages similar to @protobuf-ts/runtime

Keywords

FAQs

Package last updated on 13 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc